
package com.carsite.dao.hibernate;

import java.util.List;

import com.carsite.dao.hibernate.BaseDaoHibernate;
import com.carsite.model.CheckTable;
import com.carsite.dao.CheckTableDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class CheckTableDaoHibernate extends BaseDaoHibernate implements CheckTableDao {

    /**
     * @see com.carsite.dao.CheckTableDao#getCheckTables(com.carsite.model.CheckTable)
     */
    public List getCheckTables(final CheckTable checkTable) {
        return getHibernateTemplate().find("from CheckTable");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.
        if (checkTable == null) {
            return getHibernateTemplate().find("from CheckTable");
        } else {
            // filter on properties set in the checkTable
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(checkTable).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(CheckTable.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }*/
    }

    /**
     * @see com.carsite.dao.CheckTableDao#getCheckTable(Long ctId)
     */
    public CheckTable getCheckTable(final Long ctId) {
        CheckTable checkTable = (CheckTable) getHibernateTemplate().get(CheckTable.class, ctId);
        if (checkTable == null) {
            log.warn("uh oh, checkTable with ctId '" + ctId + "' not found...");
            throw new ObjectRetrievalFailureException(CheckTable.class, ctId);
        }

        return checkTable;
    }

    /**
     * @see com.carsite.dao.CheckTableDao#saveCheckTable(CheckTable checkTable)
     */    
    public void saveCheckTable(final CheckTable checkTable) {
        getHibernateTemplate().saveOrUpdate(checkTable);
    }

    /**
     * @see com.carsite.dao.CheckTableDao#removeCheckTable(Long ctId)
     */
    public void removeCheckTable(final Long ctId) {
        getHibernateTemplate().delete(getCheckTable(ctId));
    }
}
